#include "pch.h"
#include "include/coder.h"


//-------------------------------------------------------------------------------------
MemoryStream2::MemoryStream2(int size)
{
	m_Buffer = new char[size];
	m_capcity = size;
	m_length = 0;
	m_position = 0;
	m_isCompressed = false;
}

MemoryStream2::~MemoryStream2()
{
	SAFE_RELEASE_ARRAY(m_Buffer);
}

char* MemoryStream2::GetBuffer()
{
	return m_Buffer;
}

char* MemoryStream2::GetWritePosition()
{
	return m_Buffer + m_position;
}

int   MemoryStream2::GetLength()
{
	return m_length;
}

int   MemoryStream2::GetCapcity()
{
	return m_capcity;
}

int   MemoryStream2::GetSpace()
{
	return m_capcity - m_length;
}

void MemoryStream2::Clear()
{
	m_length = 0;
	m_position = 0;
}

void MemoryStream2::Seek(int position)
{
	m_position = position;
	if (m_length< position)
	{
		m_length = position;
	}
}

void MemoryStream2::Advance(int len)
{
	m_length += len;
	m_position += len;
}

bool MemoryStream2::Write(const char* data, int len)
{
	if (len > GetSpace())
	{
		return false;
	}
	memcpy(m_Buffer + m_position, data, len);
	m_position += len;
	if (m_position > m_length)
	{
		m_length = m_position;
	}
	return true;
}

bool MemoryStream2::Compress(int headsize)
{
	return true;
}

static MemoryStream2* instance = NULL;
MemoryStream2* MemoryStream2::Get(bool autoclear /*= true*/)
{
	if (!instance)
	{
		instance = new MemoryStream2(4096);
	}
	if (autoclear && instance)
	{
		instance->Clear();
	}
	return instance;
}


ZlibTool::ZlibTool(int size)
{

}

ZlibTool::~ZlibTool()
{

}

bool ZlibTool::Compress(const char* buf, int len)
{
	return true;
}

bool ZlibTool::DeCompress(const char* buf, int len)
{
	return true;
}

ZlibTool* ZlibTool::Get()
{
	return NULL;
}
